package com.crm.jdy.controller.client;

import com.crm.jdy.common.dto.ActivitiBasunessDto;
import com.crm.jdy.common.dto.ClientChargeInfoDto;
import com.crm.jdy.common.pojo.ActivitiBasuness;
import com.crm.jdy.common.pojo.ClientChargeInfo;
import com.crm.jdy.common.utils.AesEncryptUtils;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.client.ActivitiBasunessService;
import com.crm.jdy.service.client.ClientChargeInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipInputStream;

/**
*
* <p>说明： 业务流程审批API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年3月29日
*
*/
@Validated
@Api(tags = "activitiBasuness", description = "业务流程审批")
@RestController
@RequestMapping("/activitiBasuness")
public class ActivitiBasunessController{

    @Reference(version = "${service.version}", check = false)
    ActivitiBasunessService activitiBasunessService;

    @RateLimit()
    @ApiOperation("业务流程审批信息")
    @PostMapping("/seleteChargeInfo")
    public ResultVo seleteChargeInfo( @RequestBody ActivitiBasunessDto basuness){
        PageInfo<ActivitiBasuness> list = activitiBasunessService.seleteActivitiBasuness(basuness);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新业务流程审批")
    @PostMapping("/updatChargeInfo")
    public ResultVo updatChargeInfo(@ApiParam(value = "basuness", required = true)
                                    @Validated @RequestBody ActivitiBasuness basuness){
        boolean index = activitiBasunessService.updateActivitiBasuness(basuness);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加业务流程审批")
    @PostMapping("/addChargeInfo")
    public ResultVo addChargeInfo(@ApiParam(name = "basuness", required = false)
                                  @Validated @RequestBody ActivitiBasuness basuness){
        boolean list  = activitiBasunessService.addActivitiBasuness(basuness);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("删除业务流程审批")
    @DeleteMapping("deleteChargeInfo/{aid}")
    public ResultVo deleteChargeInfo(@NotNull @ApiParam(name = "aid", value = "aid", required = true) @PathVariable String  aid){
             boolean b = activitiBasunessService.removeActivitiBasuness(aid);
            if(b){
                return ResultVo.success();
            }

//        String content = cid;
//        System.out.println("加密前：" + content);
//        String encrypt = AesEncryptUtils.encrypt(content, AesEncryptUtils.KEY);
//        System.out.println("加密后：" + encrypt);
//        String aid = "test";
//        String password = "12345678";
        //加密
//        System.out.println("加密前：" + aid);
//        byte[] encryptResult = AesEncryptUtils.encrypt(aid, password);
//        String encryptResultStr = AesEncryptUtils.parseByte2HexStr(encryptResult);
//        System.out.println("加密后：" + encryptResultStr);
        //解密
//        byte[] decryptFrom = AesEncryptUtils.parseHexStr2Byte(aid);
//        byte[] decryptResult = AesEncryptUtils.decrypt(decryptFrom,password);
//        System.out.println("解密后：" + new String(decryptResult));

        return ResultVo.failed(aid);
    }





}